package Person.ith_34;

import java.util.Scanner;

public class M {
    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayUtil a = new ArrayUtil();

int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
    arr[i]=sc.nextInt();
}
int m = sc.nextInt();
for(int i = 0;i<m;i++){
    int begin = sc.nextInt();
    int end = sc.nextInt();
    a.finnMax(arr,begin,end);
}

    }
}
class ArrayUtil{
    public void finnMax(int arr[],int begin,int end){
if(begin>=end){
    System.out.println("java.lang.IllegalArgumentException: begin:"+begin+" >= end:"+end);
}else if(begin<0){
    System.out.println("java.lang.IllegalArgumentException: begin:"+begin+" < 0");
}else if(end>arr.length){
    System.out.println("java.lang.IllegalArgumentException: end:"+end+" > arr.length");
}else{
    int max=0;
    for(int i=begin;i<end;i++){
        if(arr[i]>max){
            max=arr[i];
        }
    }
    System.out.println(max);
}

    }

}